/**
 * 神州信息(2012)
 */
package net.abbp.report.view.cell.io;

import net.abbp.core.util.NumberUtils;
import net.abbp.core.util.StringUtils;
import net.abbp.report.model.io.IValueIO;
import net.abbp.report.view.cell.value.JsDataValue;

import org.dom4j.Element;

/**
 * JsDataValue写入写出
 * 
 * @version 1.0
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ABBP 1.0
 * 
 *        <pre>
 * 历史：
 *      建立: Jul 28, 2012 lexloo
 * </pre>
 */
public class JsDataValueIO implements IValueIO {
    @Override
    public Object read(Element value) {
        JsDataValue jdv = new JsDataValue();

        jdv.setDataSourceId(value.elementText("DataSourceID"));
        jdv.setDataSourceCaption(value.elementText("DataSourceCaption"));
        jdv.setField(value.elementText("Field"));
        jdv.setFieldCaption(value.elementText("FieldCaption"));
        jdv.setType(NumberUtils.convertToInteger(value.elementText("Type")));
        jdv.setFormula(value.elementText("formula"));

        return jdv;
    }

    @Override
    public void write(Element element, Object value) {
        JsDataValue v = (JsDataValue) value;
        element.addElement("DataSourceID").addText(v.getDataSourceId());
        element.addElement("DataSourceCaption").addText(v.getDataSourceCaption());
        element.addElement("Field").addText(v.getField());
        element.addElement("FieldCaption").addText(v.getFieldCaption());
        element.addElement("Type").addText(String.valueOf(v.getType()));
        element.addElement("formula").addText(StringUtils.convertToString(v.getFormula(),""));
    }

}
